' flags used with waveOutOpen(), waveInOpen(), midiInOpen(), and
' midiOutOpen() to specify the type of the dwCallback parameter.
Global Const CALLBACK_TYPEMASK = &H70000 ' callback type mask
Global Const CALLBACK_NULL = &H0& ' no callback
Global Const CALLBACK_WINDOW = &H10000 ' dwCallback is a HWND
Global Const CALLBACK_TASK = &H20000 ' dwCallback is a HTASK
Global Const CALLBACK_FUNCTION = &H30000 ' dwCallback is a FARPROC
' MIDI function prototypes
Declare Function midiOutGetNumDevs Lib "MMSYSTEM" () As Integer
Declare Function midiOutGetDevCaps Lib "MMSYSTEM" (ByVal udeviceid As Integer, lpCaps As MIDIOUTCAPS, ByVal uSize As Integer) As Integer
Declare Function midiOutGetVolume Lib "MMSYSTEM" (ByVal udeviceid As Integer, lpdwvolume As Long) As Integer
Declare Function midiOutSetVolume Lib "MMSYSTEM" (ByVal udeviceid As Integer, ByVal dwVolume As Long) As Integer
Declare Function midiOutGetErrorText Lib "MMSYSTEM" (ByVal uError As Integer, ByVal lpText As String, ByVal uSize As Integer) As Integer
Declare Function midiOutOpen Lib "MMSYSTEM" (lphMidiOut As Integer, ByVal udeviceid As Integer, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Integer
Declare Function midiOutClose Lib "MMSYSTEM" (ByVal hmidiout As Integer) As Integer
Declare Function midiOutPrepareHeader Lib "MMSYSTEM" (ByVal hmidiout As Integer, lphMidiOut As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiOutUnprepareHeader Lib "MMSYSTEM" (ByVal hmidiout As Integer, lphMidiOut As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiOutShortMsg Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal dwMsg As Long) As Integer
Declare Function midiOutLongMsg Lib "MMSYSTEM" (ByVal hmidiout As Integer, lphMidiOut As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiOutReset Lib "MMSYSTEM" (ByVal hmidiout As Integer) As Integer
Declare Function midiOutCachePatches Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal uBank As Integer, ByVal PatchArray As Long, ByVal uFlags As Integer) As Integer
Declare Function midiOutCacheDrumPatches Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal uPatch As Integer, lpwKeyArray As Integer, ByVal uFlags As Integer) As Integer
Declare Function midiOutGetID Lib "MMSYSTEM" (ByVal hmidiout As Integer, lpudeviceid As Integer) As Integer
Declare Function midiOutMessage Lib "MMSYSTEM" (ByVal hmidiout As Integer, ByVal uMessage As Integer, ByVal dw1 As Long, ByVal dw2 As Long) As Long
Declare Function midiInGetNumDevs Lib "MMSYSTEM" () As Integer
Declare Function midiInGetDevCaps Lib "MMSYSTEM" (ByVal udeviceid As Integer, lpCaps As MIDIINCAPS, ByVal uSize As Integer) As Integer
Declare Function midiInGetErrorText Lib "MMSYSTEM" (ByVal uError As Integer, ByVal lpText As String, ByVal uSize As Integer) As Integer
Declare Function midiInOpen Lib "MMSYSTEM" (lphMidiIn As Integer, ByVal udeviceid As Integer, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Integer
Declare Function midiInClose Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInPrepareHeader Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpMidiInHdr As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiInUnprepareHeader Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpMidiInHdr As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiInAddBuffer Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpMidiInHdr As MIDIHDR, ByVal uSize As Integer) As Integer
Declare Function midiInStart Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInStop Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInReset Lib "MMSYSTEM" (ByVal hMidiIn As Integer) As Integer
Declare Function midiInGetID Lib "MMSYSTEM" (ByVal hMidiIn As Integer, lpudeviceid As Integer) As Integer
Declare Function midiInMessage Lib "MMSYSTEM" (ByVal hMidiIn As Integer, ByVal uMessage As Integer, ByVal dw1 As Long, ByVal dw2 As Long) As Long
Sub inerr (ByVal merr As Integer)
Dim s As String
Dim x As Integer
s = Space(MAXERRORLENGTH)
x = midiInGetErrorText(merr, s, MAXERRORLENGTH)
'If Not gdebug Then
MsgBox s
'End If
End Sub
Sub midi_in_close ()
Dim merr As Integer
If m_hMidiIn <> 0 Then
merr = midiInClose(m_hMidiIn)
If Not merr = 0 Then
Call inerr(merr)
End If
m_hMidiIn = 0
End If
End Sub
Function midi_in_get_dev () As Integer
midi_in_get_dev = m_dev_id_IN
End Function
Function midi_in_open (ByVal h_wnd As Integer) As Integer
Dim merr As Integer
'
midi_in_close ' just in case (And it dont hurt)
merr = midiInOpen(m_hMidiIn, m_dev_id_IN, h_wnd, 0, CALLBACK_WINDOW)
If Not merr = 0 Then
Call inerr(merr)
End If
midi_in_open = (m_hMidiIn <> 0)
End Function
Sub midi_in_set_dev (ByVal ldev As Integer)
m_dev_id_IN = ldev
End Sub
Function midi_out_open () As Integer
Dim merr As Integer
midi_out_close ' just in case (And it dont hurt)
merr = midiOutOpen(m_hmidiout, m_dev_id_OUT, 0, 0, 0)
If Not merr = 0 Then
Call outerr(merr)
End If
midi_out_open = (m_hmidiout <> 0)
End Function
Sub midi_out_set_dev (ByVal ldev As Integer)
m_dev_id_OUT = ldev
End Sub
Sub midi_outshort_raw (ByVal d As Long)
Dim x As Integer
x = midiOutShortMsg(m_hmidiout, d)
End Sub
Sub midi_start_rec ()
Dim merr As Integer
merr = midiInStart(m_hMidiIn)
If Not merr = 0 Then
Call inerr(merr)
End If
End Sub
Sub midi_stop_rec ()
Dim merr As Integer
merr = midiInStop(m_hMidiIn)
If Not merr = 0 Then
Call inerr(merr)
End If
End Sub
Sub outerr (ByVal merr As Integer)
Dim s As String
Dim x As Integer
s = Space(MAXERRORLENGTH)
x = midiOutGetErrorText(merr, s, MAXERRORLENGTH)
'If Not gdebug Then
MsgBox s
'End If
End Sub
Sub init_combo_dev_in (c As Control)
Dim incaps As MIDIINCAPS
Dim i As Integer
For i = -1 To midiInGetNumDevs()
If 0 = midiInGetDevCaps(i, incaps, Len(incaps)) Then
c.AddItem incaps.szpname
c.ItemData(c.NewIndex) = i
End If
Next
End Sub
Sub init_combo_dev_out (c As Control)
Dim outcaps As MIDIOUTCAPS
Dim i As Integer
For i = -1 To midiOutGetNumDevs()
If 0 = midiOutGetDevCaps(i, outcaps, Len(outcaps)) Then